<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
// This test copies all the elements containing event handlers and javascript
// urls, pastes them in an editable area and verifies that no script, handlers
// or javascript urls are copied.
selection_test(
    [
        '<div id="source">^',
            '<button id="button1" onclick="sayHello()" ondblclick="sayHello()">',
                'Hello',
            '</button>',
            '<a id="anchor1" href="http://example.com/">CNN</a>',
            '<a id="anchor2" href="javascript:sayHello()">Hello</a>',
            '<iframe id="iframe1" src="javascript:var x = 1;"></iframe>',
            '<iframe id="iframe2" srcdoc="<script>var x = 1;\u003C/script>XYZ"></iframe>',
            '<form id="form1" action="javascript:sayHello()" formaction="javascript:sayHello()">',
                'This is a form<br>',
                '<img src="http://example.com">',
                '<button formaction="javascript:sayHello()">Submit.</button>',
            '</form>',
        '|</div>',
        '<div contenteditable id="target"></div>',
    ],
    selection => {
        if (!window.testRunner)
          throw 'This test requies testRunner.';
        selection.document.execCommand('Copy');
        selection.document.getElementById('source').innerHTML = '';
        selection.collapse(selection.document.getElementById('target'), 0);
        selection.document.execCommand('Paste');
    },
    [
        '<div id="source"></div>',
        '<div contenteditable id="target">',
            '<button id="button1">Hello</button>',
            '<a href="http://example.com/" id="anchor1">CNN</a>',
            '<a id="anchor2">Hello</a>',
            '<iframe id="iframe1"></iframe>',
            '<iframe id="iframe2"></iframe>',
            '<form formaction="javascript:sayHello()" id="form1">',
                'This is a form<br>',
                '<img src="http://example.com/">',
                '<button>Submit.|</button>',
            '</form>',
        '</div>',
    ]);
</script>
